package com.examples.oryarok;

import static com.examples.oryarok.Constants.ADDRESS;
import static com.examples.oryarok.Constants.DATE;
import static com.examples.oryarok.Constants.DAY;
import static com.examples.oryarok.Constants.GENDER;
import static com.examples.oryarok.Constants.NAME;
import static com.examples.oryarok.Constants.NOTE;
import static com.examples.oryarok.Constants.NUM_CONTACTS;
import static com.examples.oryarok.Constants.PHONE1;
import static com.examples.oryarok.Constants.STATUS;
import static com.examples.oryarok.Constants.TABLE_NAME;
import static com.examples.oryarok.Constants.TIME;
import static com.examples.oryarok.Constants.TYPE;
import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddEntry extends Activity {
	private MeetDataDbHelper meetEntry;
	private EditText mListName;
	private EditText mListDate;
	private EditText mListTime;
	private EditText mListPhone;
	private Button mListAddButt;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_entry);
        mListName = (EditText)findViewById(R.id.menu_add_user);
        mListDate = (EditText)findViewById(R.id.menu_add_date);
        mListTime = (EditText)findViewById(R.id.menu_add_time);
        mListPhone = (EditText)findViewById(R.id.menu_add_phone);
        mListAddButt= (Button)findViewById(R.id.but_menu_add);
        
        mListAddButt.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				EntryAdder();
				finish();
				
			}
		});
    }
	
	private void EntryAdder() {
		String name = mListName.getText().toString();
		String date = mListDate.getText().toString();
		String time = mListTime.getText().toString();
		String phone = mListPhone.getText().toString();
		
		meetEntry = new MeetDataDbHelper(this);
        try {
        	SQLiteDatabase db = meetEntry.getWritableDatabase();
    		ContentValues values = new ContentValues();
    		values.put(DATE, date);
    		values.put(DAY, "Tue");
    		values.put(TIME, time);
    		values.put(NAME, name);
    		values.put(GENDER, "M");
    		values.put(PHONE1, phone);
    		values.put(ADDRESS, "1151/25");
    		values.put(STATUS, "ishur");
    		values.put(TYPE, "miphgash");
    		values.put(NUM_CONTACTS, 2);
    		values.put(NOTE, "bla bla");
    		db.insertOrThrow(TABLE_NAME, null, values);
        	
        }
        finally {
        	meetEntry.close();
        }
		
	}

}
